<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
$time_start = getMicro_Time();
include_once("ListResult.php");
$time_end = getMicro_Time();

$fp = @file($strTemplatePath."List.html");
$fp = implode("", $fp);
$fp = setHTMLCharset($fp);
	$fp = str_replace("{Show_LottoID}", $_data["LottoID"], $fp);
	$fp = str_replace("{Show_GambleID}", $_data["GambleID"], $fp);
	$fp = str_replace("{Show_Bet_Type}", $_data["Bet_Type"], $fp);
	$fp = str_replace("{Show_PayupDate_0}", $data["PayupDate_x"][0], $fp);
	$fp = str_replace("{Show_PayupDate_1}", $data["PayupDate_x"][1], $fp);
	$fp = str_replace("{LottoContent}", (empty($_data["LottoID"]))?"All":$_arrLotto[$_data["LottoID"]]["Lotto_".$_intLang], $fp);
	$fp = str_replace("{BetTypeContent}", (empty($_data["Bet_Type"]))?"All":$_arrBet_Type[$_arrLotto[$_data["LottoID"]]["LType"]][$_data["Bet_Type"]], $fp);
	$fp = str_replace("{Show_Types}", ((empty($_data["Types"]))?"MainAgent":$_data["Types"]), $fp);
	$fp = str_replace("{MainID}", $_data["MainID"], $fp);

	if(!empty($_data["StockID"])){
		$fp = preg_replace("/<!--@ ShowBar Start @\/\/-->.+<!--@ ShowBar End @\/\/-->/s", "", $fp);
	}

	while(list($k, $v) = each($_strAccount_Main)){
		$fp = str_replace("{".$k."}", $v, $fp);
	}

	preg_match("/<!--@ AgentResult Start @\/\/-->(.+)<!--@ AgentResult End @\/\/-->/s", $fp, $A);
	preg_match("/<!--@ GAgentResult Start @\/\/-->(.+)<!--@ GAgentResult End @\/\/-->/s", $fp, $G);
	preg_match("/<!--@ SuppleAgentResult Start @\/\/-->(.+)<!--@ SuppleAgentResult End @\/\/-->/s", $fp, $SA);
	preg_match("/<!--@ SuppleGAgentResult Start @\/\/-->(.+)<!--@ SuppleGAgentResult End @\/\/-->/s", $fp, $SG);
	preg_match("/<!--@ ALLResult Start @\/\/-->(.+)<!--@ ALLResult End @\/\/-->/s", $fp, $S);
	$sumtotals = 0;
	$sumMemStake = 0;
	$sumSubIncome = 0;
	$sumSubResult = 0;
	$sumSubRateResult = 0;
	$sumMainResult = 0;
	$sumMainRateResult = 0;
	$sumrealMemStake = 0;
	$sumMainComm = 0;
	$Ctotals = 0;
	$CMemStake = 0;
	$CSubIncome = 0;
	$CSubResult = 0;
	$CSubRateResult = 0;
	$CMainResult = 0;
	$CMainRateResult = 0;
	$CrealMemStake = 0;
	$MainID = "";
	//一般帳
	if(is_array($arrRows[0])){
		while(list($k, $Rows) = each($arrRows[0])){
			if($intReportType == 0 && !empty($MainID) && $MainID != $Rows -> MainID){
				$tmpG = str_replace("{Show_GAgent}", $arrAccount[$MainID], $G[1]);
				$tmpG = str_replace("{sumtotals}", number_format($sumtotals), $tmpG);
				$tmpG = str_replace("{sumMemStake}", sprintf("%.1f",$sumMemStake), $tmpG);
				$tmpG = str_replace("{sumSubIncome}", sprintf("%.1f",$sumSubIncome), $tmpG);
				$tmpG = str_replace("{sumSubResult}", sprintf("%.1f",$sumSubResult), $tmpG);
				$tmpG = str_replace("{Percentage}", round($sumrealMemStake / $CrealMemStake,4), $tmpG);
				$tmpG = str_replace("{sumSubRateResult}", sprintf("%.1f",$sumSubRateResult), $tmpG);
				$tmpG = str_replace("{sumMainResult}", sprintf("%.1f",$sumMainResult), $tmpG);
				$tmpG = str_replace("{sumMainComm}", sprintf("%.2f",$sumMainComm), $tmpG);
				$tmpG = str_replace("{sumMainRateWin}", sprintf("%.1f",$sumSubRateResult - $sumMainRateResult - $sumMainComm), $tmpG);
				//$tmpG = str_replace("{sumMainWin}", sprintf("%.1f",($sumMainResult - $sumMainRateResult)), $tmpG);
				$tmpG = str_replace("{sumMainWin}", sprintf("%.1f",$sumSubRateResult - $sumMainRateResult), $tmpG);
				$tmpG = str_replace("{sumMainRateResult}", sprintf("%.1f",$sumMainRateResult), $tmpG);
				$tmpG = str_replace("{sumrealMemStake}", sprintf("%.1f",$sumrealMemStake), $tmpG);
				$strCon .= $tmpG;
				$sumtotals = 0;
				$sumMemStake = 0;
				$sumSubIncome = 0;
				$sumSubResult = 0;
				$sumSubRateResult = 0;
				$sumMainResult = 0;
				$sumMainRateResult = 0;
				$sumrealMemStake = 0;
				$sumMainComm = 0;
			}
			$MainID = $Rows -> MainID;
			$realMemStake = $Rows -> realMemStake;
			if($intReportType == 0){
				$tmpA = str_replace("{Show_Agent}", $arrAccount[$Rows -> SubID], $A[1]);
				$tmpA = str_replace("{Show_SubID}", $Rows -> SubID, $tmpA);
				$tmpA = str_replace("{Show_MainID}", $Rows -> MainID, $tmpA);
			}elseif($intReportType == 1){
				$tmpA = str_replace("{Show_Agent}", $_arrBet_Type[$_arrLotto[$Rows -> LottoID]["LType"]][$Rows -> Bet_Type], $A[1]);
				$tmpA = str_replace("Account('{Show_SubID}','{Show_MainID}')", "ReportType('".$Rows -> LottoID."','".$Rows -> Bet_Type."', 0)", $tmpA);
				$tmpA = str_replace("{Show_MainID}", $Rows -> MainID, $tmpA);
			}
			$tmpA = str_replace("{totals}", number_format($Rows -> totals), $tmpA);
			$tmpA = str_replace("{MemStake}", sprintf("%.1f",$Rows -> MemStake), $tmpA);
			$tmpA = str_replace("{SubIncome}", sprintf("%.1f",$Rows -> SubIncome), $tmpA);
			$tmpA = str_replace("{SubResult}", sprintf("%.1f",$Rows -> SubResult), $tmpA);
			$tmpA = str_replace("{MainRate}", $Rows -> MainRate, $tmpA);
			$tmpA = str_replace("{SubRate}", $Rows -> SubRate, $tmpA);
			$tmpA = str_replace("{SubMainRate}", ($Rows -> SubRate - $Rows -> MainRate), $tmpA);
			$tmpA = str_replace("{SubExchangeRate}", $Rows -> MemExchangeRate, $tmpA);
			$tmpA = str_replace("{SubRateResult}", sprintf("%.1f",$Rows -> SubRateResult), $tmpA);
			$tmpA = str_replace("{MainResult}", sprintf("%.1f",$Rows -> MainResult), $tmpA);
			$tmpA = str_replace("{MainComm}", sprintf("%.2f",$Rows -> MainComm), $tmpA);
			$tmpA = str_replace("{MainRateWin}", sprintf("%.1f",$Rows -> SubRateResult - $Rows -> MainRateResult - $Rows -> MainComm), $tmpA);
			//$tmpA = str_replace("{MainWin}", sprintf("%.1f",($Rows -> MainResult - $Rows -> MainRateResult)), $tmpA);
			$tmpA = str_replace("{MainWin}", sprintf("%.1f",($Rows -> SubRateResult - $Rows -> MainRateResult)), $tmpA);
			$tmpA = str_replace("{MainRateResult}", sprintf("%.1f",$Rows -> MainRateResult), $tmpA);
			$tmpA = str_replace("{realMemStake}", sprintf("%.1f",$realMemStake), $tmpA);
			$strCon .= $tmpA;
			$sumtotals += $Rows -> totals;
			$sumMemStake += $Rows -> MemStake;
			$sumSubIncome += $Rows -> SubIncome;
			$sumSubResult += $Rows -> SubResult;
			$sumSubRateResult += $Rows -> SubRateResult;
			$sumMainResult += $Rows -> MainResult;
			$sumMainRateResult += $Rows -> MainRateResult;
			$sumrealMemStake += $realMemStake;
			$sumMainComm += $Rows -> MainComm;

			$Ctotals += $Rows -> totals;
			$CMemStake += $Rows -> MemStake;
			$CSubIncome += $Rows -> SubIncome;
			$CSubResult += $Rows -> SubResult;
			$CSubRateResult += $Rows -> SubRateResult;
			$CMainResult += $Rows -> MainResult;
			$CMainRateResult += $Rows -> MainRateResult;
			$CrealMemStake += $realMemStake;
			$CrealMainComm += $Rows -> MainComm;
		}
	}
	$tmpG = str_replace("{Show_GAgent}", $arrAccount[$MainID], $G[1]);
	$tmpG = str_replace("{sumtotals}", number_format($sumtotals), $tmpG);
	$tmpG = str_replace("{sumMemStake}", sprintf("%.1f",$sumMemStake), $tmpG);
	$tmpG = str_replace("{sumSubIncome}", sprintf("%.1f",$sumSubIncome), $tmpG);
	$tmpG = str_replace("{sumSubResult}", sprintf("%.1f",$sumSubResult), $tmpG);
	$tmpG = str_replace("{sumSubRateResult}", sprintf("%.1f",$sumSubRateResult), $tmpG);
	$tmpG = str_replace("{sumMainResult}", sprintf("%.1f",$sumMainResult), $tmpG);
	$tmpG = str_replace("{sumMainComm}", sprintf("%.2f",$sumMainComm), $tmpG);
	$tmpG = str_replace("{sumMainRateWin}", sprintf("%.1f",$sumSubRateResult - $sumMainRateResult - $sumMainComm), $tmpG);
	//$tmpG = str_replace("{sumMainWin}", sprintf("%.1f",($sumMainResult - $sumMainRateResult)), $tmpG);
	$tmpG = str_replace("{sumMainWin}", sprintf("%.1f",($sumSubRateResult - $sumMainRateResult)), $tmpG);
	$tmpG = str_replace("{sumMainRateResult}", sprintf("%.1f",$sumMainRateResult), $tmpG);
	$tmpG = str_replace("{sumrealMemStake}", sprintf("%.1f",$sumrealMemStake), $tmpG);
	$strCon .= $tmpG;
	$fp = preg_replace("/<!--@ AgentResult Start @\/\/-->.+<!--@ GAgentResult End @\/\/-->/s", $strCon, $fp);


	$sumtotals = 0;
	$sumMemStake = 0;
	$sumSubIncome = 0;
	$sumSubResult = 0;
	$sumSubRateResult = 0;
	$sumMainResult = 0;
	$sumMainRateResult = 0;
	$sumrealMemStake = 0;
	$sumMainSuppleWin = 0;
	$sumMainComm = 0;
	$MainID = "";
	$strCon = "";
	//補貨帳
	if(is_array($arrRows[1])){
		while(list($k, $Rows) = each($arrRows[1])){
			$tmpA = $SA[1];
			$MainID = $Rows -> MainID;
			$realMemStake = $Rows -> realMemStake;
			if($intReportType == 0){
				$tmpA = str_replace("{Show_Agent}", $arrAccount[$Rows -> SubID], $tmpA);
				$tmpA = str_replace("{Show_MainID}", $MainID, $tmpA);
				$tmpA = str_replace("Account('{Show_SubID}','{Show_MainID}')", "ReportType('".$Rows -> LottoID."','".$Rows -> Bet_Type."', 3)", $tmpA);
			}elseif($intReportType == 1){
				$tmpA = str_replace("{Show_Agent}", $_arrBet_Type[$_arrLotto[$Rows -> LottoID]["LType"]][$Rows -> Bet_Type], $tmpA);
				$tmpA = str_replace("BetSupple('{Show_MainID}')", "ReportType('".$Rows -> LottoID."','".$Rows -> Bet_Type."', 3)", $tmpA);
			}
			$tmpA = str_replace("{totals}", number_format($Rows -> totals), $tmpA);
			$tmpA = str_replace("{MemStake}", sprintf("%.1f",$Rows -> MemStake), $tmpA);
			$tmpA = str_replace("{SubIncome}", sprintf("%.1f",$Rows -> SubIncome), $tmpA);
			$tmpA = str_replace("{SubResult}", sprintf("%.1f",$Rows -> SubResult), $tmpA);
			$tmpA = str_replace("{MainRate}", $Rows -> MainRate, $tmpA);
			$tmpA = str_replace("{SubRate}", $Rows -> SubRate, $tmpA);
			$tmpA = str_replace("{SubMainRate}", ($Rows -> SubRate - $Rows -> MainRate), $tmpA);
			$tmpA = str_replace("{SubExchangeRate}", $Rows -> MemExchangeRate, $tmpA);
			$tmpA = str_replace("{SubRateResult}", sprintf("%.1f",$Rows -> SubRateResult), $tmpA);
			$tmpA = str_replace("{MainResult}", sprintf("%.1f",$Rows -> MainResult), $tmpA);
			$tmpA = str_replace("{MainComm}", sprintf("%.2f",$Rows -> MainComm), $tmpA);
			$tmpA = str_replace("{MainRateWin}", sprintf("%.1f",0), $tmpA);
			$tmpA = str_replace("{MainWin}", sprintf("%.1f",$sumMainSuppleWin), $tmpA);
			$tmpA = str_replace("{MainRateResult}", sprintf("%.1f",$Rows -> MainRateResult), $tmpA);
			$tmpA = str_replace("{realMemStake}", sprintf("%.1f",$realMemStake), $tmpA);
			$strCon .= $tmpA;
			$sumtotals += $Rows -> totals;
			$sumMemStake += $Rows -> MemStake;
			$sumSubIncome += $Rows -> SubIncome;
			$sumSubResult += $Rows -> SubResult;
			$sumSubRateResult += $Rows -> SubRateResult;
			$sumMainResult += $Rows -> MainResult;
			$sumMainRateResult += $Rows -> MainRateResult;
			$sumrealMemStake += $realMemStake;
			$sumMainSuppleWin += $Rows -> MainRateResult*-1;
			$sumMainComm += $Rows -> MainComm;

			$Ctotals += $Rows -> totals;
			$CMemStake += $Rows -> MemStake;
			$CSubIncome += $Rows -> SubIncome;
			$CSubResult += $Rows -> SubResult;
			$CSubRateResult += $Rows -> SubRateResult;
			$CMainResult += $Rows -> MainResult;
			$CMainRateResult += $Rows -> MainRateResult;
			$CrealMemStake += $realMemStake;
			$CrealMainComm += $Rows -> MainComm;
		}
	}
	$tmpG = str_replace("{Show_GAgent}", $arrAccount[$MainID], $G[1]);
	$tmpG = str_replace("{sumtotals}", number_format($sumtotals), $tmpG);
	$tmpG = str_replace("{sumMemStake}", sprintf("%.1f",$sumMemStake), $tmpG);
	$tmpG = str_replace("{sumSubIncome}", sprintf("%.1f",$sumSubIncome), $tmpG);
	$tmpG = str_replace("{sumSubResult}", sprintf("%.1f",$sumSubResult), $tmpG);
	$tmpG = str_replace("{sumSubRateResult}", sprintf("%.1f",$sumSubRateResult), $tmpG);
	$tmpG = str_replace("{sumMainResult}", sprintf("%.1f",$sumMainResult), $tmpG);
	$tmpG = str_replace("{sumMainComm}", sprintf("%.2f",$sumMainComm), $tmpG);
	$tmpG = str_replace("{sumMainRateWin}", sprintf("%.1f",0), $tmpG);
	$tmpG = str_replace("{sumMainWin}", sprintf("%.1f",$sumMainSuppleWin), $tmpG);
	$tmpG = str_replace("{sumMainRateResult}", sprintf("%.1f",$sumMainRateResult), $tmpG);
	$tmpG = str_replace("{sumrealMemStake}", sprintf("%.1f",$sumrealMemStake), $tmpG);
	$strCon .= $tmpG;
	$fp = preg_replace("/<!--@ SuppleAgentResult Start @\/\/-->.+<!--@ SuppleGAgentResult End @\/\/-->/s", $strCon, $fp);

	$tmpS = str_replace("{Ctotals}", number_format($Ctotals), $S[1]);
	$tmpS = str_replace("{CMemStake}", sprintf("%.1f",$CMemStake), $tmpS);
	$tmpS = str_replace("{CSubIncome}", sprintf("%.1f",$CSubIncome), $tmpS);
	$tmpS = str_replace("{CSubResult}", sprintf("%.1f",$CSubResult), $tmpS);
	$tmpS = str_replace("{CSubRateResult}", sprintf("%.1f",$CSubRateResult), $tmpS);
	$tmpS = str_replace("{CMainResult}", sprintf("%.1f",$CMainResult), $tmpS);
	$tmpS = str_replace("{CMainComm}", sprintf("%.2f",$CrealMainComm), $tmpS);
	$tmpS = str_replace("{CMainRateWin}", sprintf("%.1f",$CSubRateResult - $CMainRateResult + $sumMainSuppleWin - $CrealMainComm), $tmpS);
	//$tmpS = str_replace("{CMainWin}", sprintf("%.1f",($CMainResult - $CMainRateResult + $sumMainSuppleWin)), $tmpS);
	$tmpS = str_replace("{CMainWin}", sprintf("%.1f",$CSubRateResult - $CMainRateResult + $sumMainSuppleWin), $tmpS);
	$tmpS = str_replace("{CMainRateResult}", sprintf("%.1f",$CMainRateResult), $tmpS);
	$tmpS = str_replace("{CrealMemStake}", sprintf("%.1f",$CrealMemStake), $tmpS);
	$fp = preg_replace("/<!--@ ALLResult Start @\/\/-->.+<!--@ ALLResult End @\/\/-->/s", $tmpS, $fp);

$fp .= "\n<a style='font-size: 10px; color: #DDDDDD'>".(string)($time_end - $time_start)."</a>";
//輸出
WebOutputHTML($fp, 1);
?>